import { defineComponent, PropType, reactive } from 'vue';
import { useControlController, useNamespace } from '@ibiz-template/vue3-util';
import { IControl } from '@ibiz/model-core';
import { IControlProvider } from '@ibiz-template/runtime';
import { ResourceScheduleTableController } from './resource-schedule-table.controller';
import './resource-schedule-table.scss';

export const ResourceScheduleTable = defineComponent({
  name: 'IBizResourceScheduleTable',
  props: {
    /**
     * @description 模型数据
     */
    modelData: { type: Object as PropType<IControl>, required: true },
    /**
     * @description 应用上下文对象
     */
    context: { type: Object as PropType<IContext>, required: true },
    /**
     * @description 视图参数对象
     * @default {}
     */
    params: { type: Object as PropType<IParams>, default: () => ({}) },
    /**
     * @description 部件适配器
     */
    provider: { type: Object as PropType<IControlProvider> },
  },
  setup() {
    const c = useControlController(
      (...args) => new ResourceScheduleTableController(...args),
    );
    const ns = useNamespace('resource-schedule-table');

    const resources = reactive([
      {
        id: 'room-a',
        name: 'A会议室',
        data: {
          capacity: 50,
          equipment: ['投影仪', '音响系统', '白板'],
          location: '主楼3层',
        },
      },
      {
        id: 'room-b',
        name: 'B会议室',
        data: {
          capacity: 30,
          equipment: ['视频会议系统', '投影仪'],
          location: '主楼2层',
        },
      },
      {
        id: 'room-c',
        name: 'C会议室',
        data: {
          capacity: 100,
          equipment: ['大屏显示器', '音响系统', '无线麦克风', '投影仪'],
          location: '副楼1层',
        },
      },
    ]);

    const tasks = reactive([
      {
        id: 'course-001',
        name: '项目管理基础',
        start: new Date('2025-09-30T09:00:00'),
        end: new Date('2025-09-30T10:30:00'),
        resourceId: 'room-a',
        data: { instructor: '王教授', students: 25, type: '理论课' },
      },
      {
        id: 'course-002',
        name: '需求工程实践',
        start: new Date('2025-09-30T10:00:00'),
        end: new Date('2025-09-30T12:00:00'),
        resourceId: 'room-a',
        data: { instructor: '李博士', students: 20, type: '实践课' },
      },
      {
        id: 'course-003',
        name: '高级架构设计',
        start: new Date('2025-09-30T22:00:00'),
        end: new Date('2025-10-01T06:00:00'),
        resourceId: 'room-b',
        data: { instructor: '张专家', students: 15, type: '研讨会' },
      },
      {
        id: 'course-004',
        name: '数据库优化技巧',
        start: new Date('2025-10-01T14:00:00'),
        end: new Date('2025-10-01T16:00:00'),
        resourceId: 'room-c',
        data: { instructor: '赵工程师', students: 60, type: '专题讲座' },
      },
      {
        id: 'course-005',
        name: '前端框架应用',
        start: new Date('2025-10-02T09:00:00'),
        end: new Date('2025-10-02T18:00:00'),
        resourceId: 'room-a',
        data: { instructor: '陈讲师', students: 30, type: '实训课' },
      },
      {
        id: 'course-006',
        name: '微服务架构',
        start: new Date('2025-10-02T10:00:00'),
        end: new Date('2025-10-02T17:00:00'),
        resourceId: 'room-b',
        data: { instructor: '刘高工', students: 25, type: '深度讲解' },
      },
      {
        id: 'course-007',
        name: '软件测试方法',
        start: new Date('2025-10-03T16:00:00'),
        end: new Date('2025-10-04T10:00:00'),
        resourceId: 'room-a',
        data: { instructor: '孙老师', students: 20, type: '实验课' },
      },
      {
        id: 'course-008',
        name: 'DevOps实战',
        start: new Date('2025-10-04T09:00:00'),
        end: new Date('2025-10-04T15:00:00'),
        resourceId: 'room-c',
        data: { instructor: '周总监', students: 45, type: '工作坊' },
      },
      {
        id: 'course-009',
        name: '移动应用开发',
        start: new Date('2025-10-05T11:00:00'),
        end: new Date('2025-10-05T13:00:00'),
        resourceId: 'room-b',
        data: { instructor: '吴专家', students: 18, type: '技术分享' },
      },
      {
        id: 'course-010',
        name: '信息安全防护',
        start: new Date('2025-10-05T12:00:00'),
        end: new Date('2025-10-05T14:00:00'),
        resourceId: 'room-b',
        data: { instructor: '郑教授', students: 22, type: '专题报告' },
      },
      {
        id: 'course-011',
        name: '用户体验设计',
        start: new Date('2025-10-06T10:00:00'),
        end: new Date('2025-10-06T12:00:00'),
        resourceId: 'room-a',
        data: { instructor: '钱设计师', students: 28, type: '案例分析' },
      },
      {
        id: 'course-012',
        name: '云计算平台应用',
        start: new Date('2025-10-07T00:00:00'),
        end: new Date('2025-10-07T05:00:00'),
        resourceId: 'room-b',
        data: { instructor: '范冰', students: 35, type: '实操训练' },
      },
      {
        id: 'course-013',
        name: '人工智能导论',
        start: new Date('2025-10-07T09:00:00'),
        end: new Date('2025-10-07T17:00:00'),
        resourceId: 'room-c',
        data: { instructor: '林教授', students: 80, type: '公开课' },
      },
      {
        id: 'course-014',
        name: '大数据分析',
        start: new Date('2025-10-08T09:00:00'),
        end: new Date('2025-10-08T11:00:00'),
        resourceId: 'room-a',
        data: { instructor: '黄博士', students: 26, type: '理论课' },
      },
      {
        id: 'course-015',
        name: '敏捷开发实践',
        start: new Date('2025-10-09T22:00:00'),
        end: new Date('2025-10-10T08:00:00'),
        resourceId: 'room-b',
        data: { instructor: '许教练', students: 30, type: '工作坊' },
      },
      {
        id: 'course-016',
        name: '区块链技术',
        start: new Date('2025-10-10T13:00:00'),
        end: new Date('2025-10-10T15:00:00'),
        resourceId: 'room-c',
        data: { instructor: '何专家', students: 40, type: '技术讲座' },
      },
      {
        id: 'course-017',
        name: '毕业设计指导',
        start: new Date('2025-10-11T14:00:00'),
        end: new Date('2025-10-12T10:00:00'),
        resourceId: 'room-b',
        data: { instructor: '邓教授', students: 12, type: '辅导课' },
      },
      {
        id: 'course-018',
        name: '学术论文写作',
        start: new Date('2025-10-12T09:00:00'),
        end: new Date('2025-10-12T17:00:00'),
        resourceId: 'room-a',
        data: { instructor: '胡研究员', students: 22, type: '专题课' },
      },
      {
        id: 'course-019',
        name: '职业规划讲座',
        start: new Date('2025-10-13T10:00:00'),
        end: new Date('2025-10-13T16:00:00'),
        resourceId: 'room-b',
        data: { instructor: '郭HR', students: 100, type: '公开讲座' },
      },
      {
        id: 'course-020',
        name: '学期总结大会',
        start: new Date('2025-10-14T15:00:00'),
        end: new Date('2025-10-15T10:00:00'),
        resourceId: 'room-c',
        data: { instructor: '校领导', students: 200, type: '全校会议' },
      },
    ]);
    return {
      c,
      ns,
      resources,
      tasks,
    };
  },
  render() {
    return (
      <div class={this.ns.b()}>
        <schedule-table
          resources={this.resources}
          tasks={this.tasks}
        ></schedule-table>
      </div>
    );
  },
});
